Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watcher reporting: add email warning if CSV attachment contains values that may be interperted as formulas #44460

Merged
merged 6 commits into from
Aug 14, 2019

Conversation

jakelandis
Copy link
Contributor

@jakelandis jakelandis commented Jul 16, 2019

This commit introduces a Warning message to the emails generated by Watcher's reporting action. This change complements Kibana's CSV formula notifications (see elastic/kibana#37930). This is implemented by reading a header (kbn-csv-contains-formulas) provided by Kibana to notify to attach the Warning to the email. The wording of the warning is borrowed from Kibana's UI and may be overridden by a dynamic setting (xpack.notification.reporting.warning.kbn-csv-contains-formulas.text). This warning is enabled by default, but may be disabled via a dynamic setting xpack.notification.reporting.warning.enabled.

Note - the doc PR will need to be separate since the majority of this is documented included from the Kibana docs.

Kibana

image

image

Watcher email - HTML

image

Watcher email - Text

image

@jakelandis jakelandis added the WIP label Jul 16, 2019
@jakelandis jakelandis changed the title initial commit for watcher reporting csv email warning Watcher reporting: add email warning if CSV attachment contains values that may be interperted as formulas Jul 16, 2019
@@ -44,7 +44,7 @@ dependencies {

testCompile 'org.subethamail:subethasmtp:3.1.7'
// needed for subethasmtp, has @GuardedBy annotation
testCompile 'com.google.code.findbugs:jsr305:3.0.1'
testCompile 'com.google.code.findbugs:jsr305:3.0.2'
Copy link
Contributor Author

@jakelandis jakelandis Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is to avoid JAR hell when running tests via IntelliJ (nothing specific to the changes here)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

@jakelandis jakelandis marked this pull request as ready for review July 16, 2019 23:19
@joelgriffith
Copy link

LGTM!

}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized, that despite the current documenation, body is not actually required, will need to adjust this to always emit a warning even if the body is not defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 0acff82

Copy link
Contributor

@hub-cap hub-cap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super small nits. great stuff. LGTM.


import static javax.mail.Part.ATTACHMENT;
import static javax.mail.Part.INLINE;

public abstract class Attachment extends BodyPartSource {

private final boolean inline;
private final Set<String> warnings;

protected Attachment(String id, String name, String contentType, boolean inline) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this constructor used anymore? Im ok w/ removing it if we dont use it anywhere. Also, if we dont want a NPE down in the EmailTemplate we should check for null assignment in the other constructor, maybe with a Objects.requireNonNull. Otherwise the user is free to put null there and receive a nice NPE during warnings.addAll(attachment.getWarnings()); below. Ill add a note with here is the NPE im talking about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this constructor is still used in some cases.

I added an assert warnings != null, since this is an internal API, the variable is final, means that someone working on Watcher internals would be required to explicitly call the second constructor with null, I think the assert is sufficient to express "don't do that". ed5128f

if (attachments != null) {
for (Attachment attachment : attachments.values()) {
builder.attach(attachment);
warnings.addAll(attachment.getWarnings());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is the NPE im talking about

@jakelandis jakelandis merged commit b28f089 into elastic:master Aug 14, 2019
@jakelandis jakelandis deleted the watcher_reporting_email_warning branch August 14, 2019 16:45
jakelandis added a commit to jakelandis/elasticsearch that referenced this pull request Aug 14, 2019
…c#44460)

This commit introduces a Warning message to the emails generated by 
Watcher's reporting action. This change complements Kibana's CSV 
formula notifications (see elastic/kibana#37930). 

This is implemented by reading a header (kbn-csv-contains-formulas) 
provided by Kibana to notify to attach the Warning to the email. 
The wording of the warning is borrowed from Kibana's UI and may 
be overridden by a dynamic setting
xpack.notification.reporting.warning.kbn-csv-contains-formulas.text.
This warning is enabled by default, but may be disabled via a 
dynamic setting xpack.notification.reporting.warning.enabled.
jakelandis added a commit that referenced this pull request Aug 26, 2019
#45557)

* Watcher add email warning if CSV attachment contains formulas (#44460)

This commit introduces a Warning message to the emails generated by 
Watcher's reporting action. This change complements Kibana's CSV 
formula notifications (see elastic/kibana#37930). 

This is implemented by reading a header (kbn-csv-contains-formulas) 
provided by Kibana to notify to attach the Warning to the email. 
The wording of the warning is borrowed from Kibana's UI and may 
be overridden by a dynamic setting
xpack.notification.reporting.warning.kbn-csv-contains-formulas.text.
This warning is enabled by default, but may be disabled via a 
dynamic setting xpack.notification.reporting.warning.enabled.
@jakelandis jakelandis removed the v8.0.0 label Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants